<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <include file="Public:head"/>
    <style>
        .progress{ margin-bottom:5px;}
        .progress.active .progress-bar{background-color: #ed4e2a;background-image: none!important;color:white;}
        #orderdetail>div>p,#orderdetail>div>*{display:inline-block;}
        @media print {
            @page {
                size: 58mm  210mm;
                margin: 1mm;
            }/*订单推送*/
            #orderdetail>h1{font-size:20mm;}
            #orderdetail>p{font-size:16mm;line-height:20mm;}
            #orderdetail>div>p,#orderdetail>div>*{font-size:14mm;line-height:18mm;display:inline-block;}
        }
    </style>
</head>
<body>
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <div class="page-body">
                <div class="row">

                    <div class="col-lg-3 col-sm-3 col-xs-12">
                        <div class="well  bordered-left bordered-azure">
                            <h4 class="block">订单详情</h4><a href="javascript:void(0);" class="btn btn-palegreen" onclick="printOrder('11')">打印</a>
                            <hr>
                            <!--printstart11-->
                            <div id="orderdetail">

                            </div>
                            <!--printend11-->
                        </div>
                    </div>
                    <div class="col-lg-3 col-sm-3 col-xs-12">
                        <div class="well  bordered-left bordered-yellow">
                            <h4 class="block">借阅订单</h4>
                            <div id="order_rent">

                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-sm-3 col-xs-12">
                        <div class="well  bordered-left bordered-success">
                            <h4 class="block">购书订单</h4>
                            <div id="order_buy">

                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-sm-3 col-xs-12">
                        <div class="well  bordered-left bordered-sky">
                            <h4 class="block">活动报名</h4>
                            <div id="order_apply">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div>
        <div class="myview view_rent" style="display:none;">
            <div class="progress progress-lg progress-bordered active" onclick="getDetailRent(event)">
                <div class="progress-bar " role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                    订单号:<span class="order_id">{{order_id}}</span>&nbsp;&nbsp;&nbsp;
                    会员卡:<span class="card_id">{{card_id}}</span>&nbsp;&nbsp;&nbsp;
                    创建日期:<span class="create_time">{{create_time}}</span>&nbsp;&nbsp;
                </div>
            </div>
        </div>
        <div class="myview view_buy" style="display:none;">
            <div class="progress progress-lg progress-bordered active" onclick="getDetailBuy(event)">
                <div class="progress-bar " role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                    订单号:<span class="order_id">{{order_id}}</span>&nbsp;&nbsp;&nbsp;
                    会员卡:<span class="card_id">{{card_id}}</span>&nbsp;&nbsp;&nbsp;
                    创建日期:<span class="create_time">{{create_time}}</span>&nbsp;&nbsp;
                </div>
            </div>
        </div>
        <div class="myview view_apply" style="display:none;">
            <div class="progress progress-lg progress-bordered active" onclick="getDetailApply(event)">
                <div class="progress-bar " role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                    报名订单:<span class="apply_id">{{apply_id}}</span>&nbsp;&nbsp;&nbsp;
                    报名活动:<span class="title">{{title}}</span>&nbsp;&nbsp;&nbsp;
                    会员卡:<span class="card_id">{{card_id}}</span>&nbsp;&nbsp;&nbsp;
                    创建日期:<span class="create_time">{{create_time}}</span>&nbsp;&nbsp;
                </div>
            </div>
        </div>
        <div class="myview view_detail" style="display:none;">
            <p class="{{key}}">{{value}}</p>
        </div>
    </div>
    <div id="printHtml"></div>
</body>
<include file="Public:js"/>
<script src="http://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="/admin/js/toastr/toastr.js"></script>
<script src="/admin/js/mysound.js"></script>
<script>
    var $rent_id = '0';
    var $buy_id = '0';
    var $apply_id = '0';
    var $templete_rent=$('.myview.view_rent').html();
    var $templete_buy=$('.myview.view_buy').html();
    var $templete_apply=$('.myview.view_apply').html();
    var $templete_detail=$('.myview.view_detail').html();

    var $target_rent=$('#order_rent');
    var $target_buy=$('#order_buy');
    var $target_apply=$('#order_apply');
    var $target_detail=$('#orderdetail');
    var $loading=false;
    var $type=false;
    var $order_id = false;


    $(function () {
        var $time = 2000;
        //载入音频
        Sound.loading('notify',"/admin/audio/order_info.mp3",1);
        setInterval("refreshOrder()", $time);
    });

    function refreshOrder() {
        if($loading){
            //正在加载
            return;
        }
        $loading=true;
        getData_OrderRent();
        getData_OrderBuy();
        getData_Apply();
    }

    function getData_OrderRent() {
        $.post('{:U("getOrderRent")}',{order_id:$rent_id},function(data){
            if(data.status=='success'){
                data.data.reverse();
                $.each(data.data,function(i,item){
                    var $t=$templete_rent;
                    $t=$t.replace(/{{order_id}}/g,item.order_id);
                    $t=$t.replace(/{{card_id}}/g,item.card_id);
                    $t=$t.replace(/{{create_time}}/g,item.create_time);
                    if(item.order_id>$rent_id){
                        $rent_id=item.order_id;
                    }
                    $target_rent.prepend($t);
                    orderNotify('通知:借阅订单'+item.order_id);
                });
            }else{
                console.log(data);
            }
            //加载完毕
            $loading=false;
        },'json');
    }

    function getData_OrderBuy() {
        $.post('{:U("getOrderBuy")}',{order_id:$buy_id},function(data){
            if(data.status=='success'){
                data.data.reverse();
                $.each(data.data,function(i,item){
                    var $t=$templete_buy;
                    $t=$t.replace(/{{order_id}}/g,item.order_id);
                    $t=$t.replace(/{{card_id}}/g,item.card_id);
                    $t=$t.replace(/{{create_time}}/g,item.create_time);
                    if(item.order_id>$buy_id){
                        $buy_id=item.order_id;
                    }
                    $target_buy.prepend($t);
                    orderNotify('通知:购书订单'+item.order_id);
                });
            }else{
                console.log(data.data);
            }
            //加载完毕
            $loading=false;
        },'json');
    }

    function getData_Apply() {
        $.post('{:U("getOrderApply")}',{apply_id:$apply_id},function(data){
            if(data.status=='success'){
                data.data.reverse();
                $.each(data.data,function(i,item){
                    var $t=$templete_apply;
                    $t=$t.replace(/{{apply_id}}/g,item.apply_id);
                    $t=$t.replace(/{{title}}/g,item.title);
                    $t=$t.replace(/{{card_id}}/g,item.card_id);
                    $t=$t.replace(/{{create_time}}/g,item.create_time);
                    if(item.apply_id>$apply_id){
                        $apply_id=item.apply_id;
                    }
                    $target_apply.prepend($t);
                    orderNotify('通知:报名单号'+item.apply_id);
                });
            }else{
                console.log(data.data);
            }
            //加载完毕
            $loading=false;
        },'json');
    }

    function getDetailRent(event){
        $type = "1";
        $order_id=$(event.currentTarget).find('.order_id').html();
        clickEffect($(event.currentTarget));
        $.post('{:U("getDetailRent")}',{order_id:$order_id},function(data){
            $target_detail.html('');
            var $t='';
            $t+='<h1>借阅订单</h1>';
            $t+=$templete_detail.replace(/{{key}}/g,'order_id').replace(/{{value}}/g,'订单号:'+data.data[0].order_id);
            $t+=$templete_detail.replace(/{{key}}/g,'card_id').replace(/{{value}}/g,'会员卡号:'+data.data[0].card_id);
            $t+=$templete_detail.replace(/{{key}}/g,'create_time').replace(/{{value}}/g,'创建时间:'+data.data[0].create_time);

            var $booklist='';
            $.each(data.data,function(i,item){
                $booklist+='<span>新华码:'+item.spbs+',</span><span>书号:'+item.isbn+',</span><span>书名:'+item.sm+';</span>';
                $booklist+='<span>——————————————</span>';
            });
            $t+=$templete_detail.replace(/{{key}}/g,'booklist').replace(/{{value}}/g,'图书列表:<div>'+$booklist+'</div>');
            $adr=JSON.parse(data.data[0].address);
            $t+=$templete_detail.replace(/{{key}}/g,'adr_name').replace(/{{value}}/g,'联系人:'+$adr.name);
            $t+=$templete_detail.replace(/{{key}}/g,'adr_phone').replace(/{{value}}/g,'联系电话:'+$adr.phone);
            $address=$adr.province+$adr.city+$adr.district+$adr.address;
            $t+=$templete_detail.replace(/{{key}}/g,'adr_address').replace(/{{value}}/g,'地址:'+$address);
            $target_detail.prepend($t);
        },'json');
    }

    function getDetailBuy(event){
        $type = "1";
        $order_id=$(event.currentTarget).find('.order_id').html();
        clickEffect($(event.currentTarget));
        $.post('{:U("getDetailBuy")}',{order_id:$order_id},function(data){
            $target_detail.html('');
            var $t='';
            $t+='<h1>购书订单</h1>';
            $t+=$templete_detail.replace(/{{key}}/g,'order_id').replace(/{{value}}/g,'订单号:'+data.data[0].order_id);
            $t+=$templete_detail.replace(/{{key}}/g,'card_id').replace(/{{value}}/g,'会员卡号:'+data.data[0].card_id);
            $t+=$templete_detail.replace(/{{key}}/g,'create_time').replace(/{{value}}/g,'创建时间:'+data.data[0].create_time);

            var $booklist='';
            $.each(data.data,function(i,item){
                $booklist+='<span>新华码:'+item.spbs+',</span><span>书号:'+item.isbn+',</span><span>书名:'+item.sm+';</span>';
                $booklist+='<span>——————————————</span>';
            });
            $t+=$templete_detail.replace(/{{key}}/g,'booklist').replace(/{{value}}/g,'图书列表:<div>'+$booklist+'</div>');
            $adr=JSON.parse(data.data[0].address);
            $t+=$templete_detail.replace(/{{key}}/g,'adr_name').replace(/{{value}}/g,'联系人:'+$adr.name);
            $t+=$templete_detail.replace(/{{key}}/g,'adr_phone').replace(/{{value}}/g,'联系电话:'+$adr.phone);
            $address=$adr.province+$adr.city+$adr.district+$adr.address;
            $t+=$templete_detail.replace(/{{key}}/g,'adr_address').replace(/{{value}}/g,'地址:'+$address);
            $target_detail.prepend($t);
        },'json');
    }

    function getDetailApply(event){
        $type = "2";
        $order_id = $(event.currentTarget).find('.apply_id').html();
        $apply_id=$(event.currentTarget).find('.apply_id').html();
        clickEffect($(event.currentTarget));
        $.post('{:U("getDetailApply")}',{apply_id:$apply_id},function(data){
            $target_detail.html('');
            var $t='';
            $t+='<h1>活动报名订单</h1>';
            $t+=$templete_detail.replace(/{{key}}/g,'apply_id').replace(/{{value}}/g,'报名单号:'+data.data.apply_id);
            $t+=$templete_detail.replace(/{{key}}/g,'card_id').replace(/{{value}}/g,'会员卡号:'+data.data.card_id);
            $t+=$templete_detail.replace(/{{key}}/g,'create_time').replace(/{{value}}/g,'创建时间:'+data.data.create_time);
            $t+="<hr>";
            $t+=$templete_detail.replace(/{{key}}/g,'title').replace(/{{value}}/g,'活动:'+data.data.title);
            $t+=$templete_detail.replace(/{{key}}/g,'price_apply').replace(/{{value}}/g,'报名费:￥'+data.data.price_apply);
            $t+=$templete_detail.replace(/{{key}}/g,'price_material').replace(/{{value}}/g,'材料费:￥'+data.data.price_material);
            $t+=$templete_detail.replace(/{{key}}/g,'activity_start').replace(/{{value}}/g,'开始时间:'+data.data.activity_start);
            $t+=$templete_detail.replace(/{{key}}/g,'activity_end').replace(/{{value}}/g,'结束时间:'+data.data.activity_end);
            $t+="<hr>";
            $contactor=JSON.parse(data.data.contactor);
            $t+=$templete_detail.replace(/{{key}}/g,'contactor_name').replace(/{{value}}/g,'联系人:'+$contactor.name);
            $t+=$templete_detail.replace(/{{key}}/g,'contactor_phone').replace(/{{value}}/g,'联系电话:'+$contactor.phone);
            $target_detail.prepend($t);
        },'json');
    }

    function orderNotify($content) {
        Notify($content, 'top-right', '5000', 'info', 'fa-envelope', true);
        //提示音乐
        Sound.play('notify');
    }

    function clickEffect($this){
        if($this.hasClass('active')){
            $this.removeClass('active');
        }else{
            $this.addClass('active');
        }
    }

    var bdhtml;
    var prnhtml;
    //打印
    function printOrder(flag) {
        $.post('{:U("isPrint")}',{type:$type,order_id:$order_id},function(data){
            $order_id = false;
            $type = false;
        },'json');

        bdhtml = $('body').html(); //获得body标签内的全部html代码
        sprnstr = '<!--printstart' + flag + '-->'; //声明一个字符串，用于表示打印的起始位置
        eprnstr = '<!--printend' + flag + '-->'; //标示打印的结束位置
        prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + sprnstr.length); //查找打印的起始字符串并加上17，因为的长度为17，所以要加17，这样打印时不会把标示打印出来
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr)); //和上边的意思差不多

        console.log(flag)
        if (prnhtml.length <= 0) {
//            无可打印内容
            return;
        }
        prnhtml = '<h1 style="font-family:STXingkai;">新华书店</h1>' +
                '<p class="title">小票</p>' + prnhtml;
        if($('#print_div')==undefined){
            return;
        }
        $('#printHtml').html(prnhtml);//通过window对象得到body对象并将当前窗体的内容设置为要打印起始标示符和结束标示符之间的内容，这样打印出来就只有需要的部分，而其他没用的信息都不会有的
        $('body>div').hide();
        $('#printHtml').show();
        window.print();
        setTimeout(function () {
            $('body>div').show();
            $('#printHtml').hide();
            $(".loading-container").addClass("loading-inactive");
        }, 10);
        setTimeout("window.close();", 20);
    }
</script>
</html>
